/*
 * list.c
 *
 *  Created on: 2011-8-24
 *      Author: jfhu
 */


#include <stdio.h>
#include "list.h"

void initializelistnode(pListnode n)
{
	n->next = NULL;
}

void initializelist(pList l)
{
	l->head = l->tail = NULL;
}

void append(pListnode n, pList l)
{
	if (l == NULL) {
		printf("append: the input list is null\n");
		return;
	}
	if (l->head == NULL) {
		l->head = l->tail = n;
		return;
	}
	l->tail->next = n;
	l->tail = n;
}

pListnode popList(pList l)
{
	pListnode temp;
	if (l == NULL) {
		printf("append: the input list is null\n");
		return NULL;
	}

	temp = l->head;
	l->head = l->head->next;

	return temp;
}

void printfList(pList l)
{
	pListnode n;
	if (l == NULL) {
		printf("list:printflist: The input list is NULL\n");
		return;
	}

	 n = l->head;
	if (n == NULL) {
		printf("list:printflist: The input list is Empty\n");
		return;
	}

	while (n != NULL) {
		printf("%d ", n->value);
		n = n->next;
	}
	printf("\n");

}
